//
//  HWWelfareNewsCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/4/2.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWWelfareNewsCell: UITableViewCell {
    var titleLabel:UILabel!
    var timeLabel:UILabel!
    var contentImageView:UIImageView!
    var ingLabel:UILabel!
    var lineImageView:UIImageView!
    var model:HWWelfareCenterNewsModel? {
        didSet {
            titleLabel.text = model?.title
            timeLabel.text = model?.time
            contentImageView.sd_setImage(with: URL(string: model?.image ?? ""), completed: nil)
            ingLabel.text = "  \(model?.type ?? "")"
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWWelfareNewsCell) {
        let reUse:String = "HWWelfareNewsCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWWelfareNewsCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWWelfareNewsCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        titleLabel = HWLabel.createBoldLabel(title: "", color: "#444444", font: 14*widthScale)
        contentView.addSubview(titleLabel)
        
        timeLabel = HWLabel.createLabel(title: "", color: "#888888", font: 10*widthScale)
        contentView.addSubview(timeLabel)
        
        contentImageView = UIImageView()
        contentImageView.layer.cornerRadius = 4*widthScale
        contentImageView.contentMode = .scaleAspectFill
        contentImageView.layer.masksToBounds = true
        contentView.addSubview(contentImageView)
        
        ingLabel = HWLabel.createBoldLabel(title: "进行中", color: "#FFFFFF", font: 10*widthScale)
        ingLabel.backgroundColor = .colorWithHexString(hexString: "#F87706")
        ingLabel.layer.cornerRadius = 8*widthScale
        ingLabel.layer.masksToBounds = true
        contentImageView.addSubview(ingLabel)
        
        lineImageView = UIImageView()
        lineImageView.image = UIImage(named: "commentLine")
        contentView.addSubview(lineImageView)
    }
    
    func initFrame() -> Void {
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.right.equalTo(-20*widthScale)
            make.top.equalToSuperview()
        }
        
        timeLabel.snp.makeConstraints { make in
            make.left.right.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(4*widthScale)
        }
        
        contentImageView.snp.makeConstraints { make in
            make.left.right.equalTo(titleLabel)
            make.top.equalTo(timeLabel.snp.bottom).offset(4*widthScale)
            make.height.equalTo(126*widthScale)
        }
        
        ingLabel.snp.makeConstraints { make in
            make.top.equalTo(10*widthScale)
            make.right.equalTo(10*widthScale)
            make.height.equalTo(16*widthScale)
            make.width.equalTo(50*widthScale)
        }
        
        lineImageView.snp.makeConstraints { make in
            make.left.right.equalTo(titleLabel)
            make.top.equalTo(contentImageView.snp.bottom).offset(10*widthScale)
            make.bottom.equalTo(-10*widthScale)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
